/*
 * cadastro.java
 *
 * Created on 24 de Outubro de 2007, 13:14
 */

package cadastro;

import classes.*;
import java.io.File;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.*;
import java.sql.*;
import bd.*;
import javax.swing.text.MaskFormatter;
/**
 *
 * @author  kurumin
 */
public class cadFilmes extends javax.swing.JFrame {
    private Database bd;
    private String path;
    
    public cadFilmes(Database meuBanco, String path) {
        initComponents();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f = new filme(meuBanco);
        atores = new DefaultListModel();
        this.bd = meuBanco;
        this.path = path;
        ResultSet rs = bd.executeQueryRs("Select tipo from genero");
        try {
            while (rs.next()){
                jComboBox1.addItem(rs.getString(1));
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        consFilmes = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        botaotitulo = new javax.swing.JRadioButton();
        botaogenero = new javax.swing.JRadioButton();
        botaoclassificacao = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        txtPesquisa = new javax.swing.JTextField();
        botaoLocaliza = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblFilmes = new javax.swing.JTable();
        botaoEditar = new javax.swing.JButton();
        cadFilmes = new javax.swing.JPanel();
        jpCadFilmes = new javax.swing.JPanel();
        jlSubTitulo = new javax.swing.JLabel();
        jtfTitulo = new javax.swing.JTextField();
        JlTitulo = new javax.swing.JLabel();
        jtfSubTitulo = new javax.swing.JTextField();
        jlCodigo = new javax.swing.JLabel();
        jtfCodigo = new javax.swing.JTextField();
        jlGenero = new javax.swing.JLabel();
        jlDuracao = new javax.swing.JLabel();
        jtfDuracao = new javax.swing.JTextField();
        jlProdutora = new javax.swing.JLabel();
        jlPais = new javax.swing.JLabel();
        jlDatEstreia = new javax.swing.JLabel();
        jlClassificacao = new javax.swing.JLabel();
        jlAtoresPrinc = new javax.swing.JLabel();
        jlDiretor = new javax.swing.JLabel();
        jtfAtoresPrinc = new javax.swing.JTextField();
        BotaoAdicionar = new javax.swing.JButton();
        jtfProdutora = new javax.swing.JTextField();
        jtfPais = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jcbDublado = new javax.swing.JCheckBox();
        jtfClassificacao = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfDiretor = new javax.swing.JTextField();
        jtfTemp_cartaz = new javax.swing.JTextField();
        botaoRemover = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        try
        {
            formatadata = new MaskFormatter("##/##/####");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "hehehe");
        }
        jtfdataestreia = new JFormattedTextField(formatadata);
        jpCadfilme = new javax.swing.JPanel();
        botaoProcurar = new javax.swing.JButton();
        jlSinopse = new javax.swing.JLabel();
        botaocadastrar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlImagen = new javax.swing.JLabel();
        botaonovo = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Filmes");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        jTabbedPane1.setFont(new java.awt.Font("Dialog", 0, 12));

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        buttonGroup1.add(botaotitulo);
        botaotitulo.setFont(new java.awt.Font("Dialog", 0, 12));
        botaotitulo.setSelected(true);
        botaotitulo.setText("Titulo");
        botaotitulo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        buttonGroup1.add(botaogenero);
        botaogenero.setFont(new java.awt.Font("Dialog", 0, 12));
        botaogenero.setText("Genero");
        botaogenero.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        buttonGroup1.add(botaoclassificacao);
        botaoclassificacao.setFont(new java.awt.Font("Dialog", 0, 12));
        botaoclassificacao.setText("Classifica??o");
        botaoclassificacao.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel2.setText("Pesquisa");

        botaoLocaliza.setText("Localizar");
        botaoLocaliza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoLocalizaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(botaotitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(botaogenero, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoclassificacao))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoLocaliza, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaotitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(botaoclassificacao)
                    .addComponent(botaogenero))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoLocaliza))
                .addContainerGap())
        );

        tblFilmes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane4.setViewportView(tblFilmes);

        botaoEditar.setText("Editar");
        botaoEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout consFilmesLayout = new javax.swing.GroupLayout(consFilmes);
        consFilmes.setLayout(consFilmesLayout);
        consFilmesLayout.setHorizontalGroup(
            consFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(consFilmesLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, consFilmesLayout.createSequentialGroup()
                .addContainerGap(488, Short.MAX_VALUE)
                .addComponent(botaoEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
            .addGroup(consFilmesLayout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
                .addContainerGap())
        );
        consFilmesLayout.setVerticalGroup(
            consFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(consFilmesLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoEditar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Consulta ", consFilmes);

        jpCadFilmes.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jlSubTitulo.setFont(new java.awt.Font("Dialog", 0, 12));
        jlSubTitulo.setText("Sub Titulo");

        jtfTitulo.setPreferredSize(new java.awt.Dimension(5, 19));

        JlTitulo.setFont(new java.awt.Font("Dialog", 0, 12));
        JlTitulo.setText("Titulo");

        jlCodigo.setFont(new java.awt.Font("Dialog", 0, 12));
        jlCodigo.setText("C?digo");

        jlGenero.setFont(new java.awt.Font("Dialog", 0, 12));
        jlGenero.setText("Genero");

        jlDuracao.setFont(new java.awt.Font("Dialog", 0, 12));
        jlDuracao.setText("Dura??o");

        jlProdutora.setFont(new java.awt.Font("Dialog", 0, 12));
        jlProdutora.setText("Produtora");

        jlPais.setFont(new java.awt.Font("Dialog", 0, 12));
        jlPais.setText("Pa?s");

        jlDatEstreia.setFont(new java.awt.Font("Dialog", 0, 12));
        jlDatEstreia.setText("Data da estr?ia");

        jlClassificacao.setFont(new java.awt.Font("Dialog", 0, 12));
        jlClassificacao.setText("Classifica??o");

        jlAtoresPrinc.setFont(new java.awt.Font("Dialog", 0, 12));
        jlAtoresPrinc.setText("Atores principais");

        jlDiretor.setFont(new java.awt.Font("Dialog", 0, 12));
        jlDiretor.setText("Diretor");

        BotaoAdicionar.setText("Adicionar");
        BotaoAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoAdicionarActionPerformed(evt);
            }
        });

        jScrollPane3.setViewportView(jList1);

        jcbDublado.setFont(new java.awt.Font("Dialog", 0, 12));
        jcbDublado.setText("Dublado");
        jcbDublado.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel3.setText("Tempo em cartaz");

        botaoRemover.setText("Remover");
        botaoRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRemoverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpCadFilmesLayout = new javax.swing.GroupLayout(jpCadFilmes);
        jpCadFilmes.setLayout(jpCadFilmesLayout);
        jpCadFilmesLayout.setHorizontalGroup(
            jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadFilmesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JlTitulo)
                    .addComponent(jlSubTitulo)
                    .addComponent(jlAtoresPrinc)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCadFilmesLayout.createSequentialGroup()
                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jtfTitulo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
                            .addGroup(jpCadFilmesLayout.createSequentialGroup()
                                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jpCadFilmesLayout.createSequentialGroup()
                                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlCodigo)
                                            .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jpCadFilmesLayout.createSequentialGroup()
                                                .addComponent(jlGenero)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, Short.MAX_VALUE))
                                            .addComponent(jComboBox1, 0, 132, Short.MAX_VALUE)))
                                    .addGroup(jpCadFilmesLayout.createSequentialGroup()
                                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlProdutora)
                                            .addComponent(jtfProdutora, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(15, 15, 15)
                                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jpCadFilmesLayout.createSequentialGroup()
                                                .addComponent(jlPais)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE))
                                            .addComponent(jtfPais, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)))
                                    .addComponent(jtfSubTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
                                    .addGroup(jpCadFilmesLayout.createSequentialGroup()
                                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jtfClassificacao, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlClassificacao, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(21, 21, 21)
                                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jpCadFilmesLayout.createSequentialGroup()
                                                .addComponent(jlDiretor)
                                                .addGap(48, 48, 48))
                                            .addComponent(jtfDiretor, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))))
                                .addGap(12, 12, 12)
                                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlDatEstreia)
                                            .addComponent(jlDuracao, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jtfDuracao, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE))
                                        .addComponent(jcbDublado)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jtfdataestreia, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jtfTemp_cartaz, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpCadFilmesLayout.createSequentialGroup()
                                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                                    .addComponent(jtfAtoresPrinc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE))
                                .addGap(30, 30, 30)
                                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(botaoRemover, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                                    .addComponent(BotaoAdicionar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGap(53, 53, 53)))
                .addContainerGap())
        );
        jpCadFilmesLayout.setVerticalGroup(
            jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadFilmesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JlTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlSubTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSubTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbDublado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlCodigo)
                    .addComponent(jlGenero)
                    .addComponent(jlDuracao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfDuracao, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlProdutora)
                    .addComponent(jlDatEstreia)
                    .addComponent(jlPais))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfPais, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfProdutora, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfdataestreia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlClassificacao)
                    .addComponent(jlDiretor)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfClassificacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfDiretor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfTemp_cartaz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addComponent(jlAtoresPrinc)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfAtoresPrinc, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotaoAdicionar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(jpCadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCadFilmesLayout.createSequentialGroup()
                        .addComponent(botaoRemover)
                        .addGap(81, 81, 81))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCadFilmesLayout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        jpCadfilme.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        botaoProcurar.setFont(new java.awt.Font("Dialog", 0, 12));
        botaoProcurar.setText("Procurar");
        botaoProcurar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoProcurarActionPerformed(evt);
            }
        });

        jlSinopse.setFont(new java.awt.Font("Dialog", 0, 12));
        jlSinopse.setForeground(new java.awt.Color(51, 51, 255));
        jlSinopse.setText("Sinopse:");

        botaocadastrar.setMnemonic('G');
        botaocadastrar.setText("Gravar");
        botaocadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaocadastrarActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(10);
        jTextArea1.setRows(10);
        jTextArea1.setMaximumSize(new java.awt.Dimension(10, 100));
        jScrollPane1.setViewportView(jTextArea1);

        jScrollPane2.setViewportView(jlImagen);

        botaonovo.setMnemonic('N');
        botaonovo.setText("Novo");
        botaonovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaonovoActionPerformed(evt);
            }
        });

        jButton1.setMnemonic('D');
        jButton1.setText("Deletar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpCadfilmeLayout = new javax.swing.GroupLayout(jpCadfilme);
        jpCadfilme.setLayout(jpCadfilmeLayout);
        jpCadfilmeLayout.setHorizontalGroup(
            jpCadfilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadfilmeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpCadfilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                    .addGroup(jpCadfilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jlSinopse, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(botaoProcurar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                    .addComponent(botaonovo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                    .addComponent(botaocadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                .addContainerGap())
        );
        jpCadfilmeLayout.setVerticalGroup(
            jpCadfilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadfilmeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoProcurar)
                .addGap(15, 15, 15)
                .addComponent(jlSinopse)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addComponent(botaonovo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botaocadastrar)
                .addContainerGap())
        );

        javax.swing.GroupLayout cadFilmesLayout = new javax.swing.GroupLayout(cadFilmes);
        cadFilmes.setLayout(cadFilmesLayout);
        cadFilmesLayout.setHorizontalGroup(
            cadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cadFilmesLayout.createSequentialGroup()
                .addComponent(jpCadFilmes, javax.swing.GroupLayout.PREFERRED_SIZE, 415, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpCadfilme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        cadFilmesLayout.setVerticalGroup(
            cadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cadFilmesLayout.createSequentialGroup()
                .addGroup(cadFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jpCadfilme, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpCadFilmes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Cadastro", cadFilmes);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 585, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-596)/2, (screenSize.height-539)/2, 596, 539);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        String mensagens;
        if(f.deleta())
           mensagens = "Registro deletado com sucesso";
        else
           mensagens = "Erro ao tentar deletar o registro";
        JOptionPane.showMessageDialog(null,mensagens);
        limpa();
        grava = true;
    }//GEN-LAST:event_jButton1ActionPerformed

    private void botaocadastrarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaocadastrarActionPerformed
    {//GEN-HEADEREND:event_botaocadastrarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
         cadastrar();
    }//GEN-LAST:event_botaocadastrarActionPerformed

    private void botaoEditarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoEditarActionPerformed
    {//GEN-HEADEREND:event_botaoEditarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        editar();
    }//GEN-LAST:event_botaoEditarActionPerformed

    private void botaonovoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaonovoActionPerformed
    {//GEN-HEADEREND:event_botaonovoActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        limpa();
        grava=true;
    }//GEN-LAST:event_botaonovoActionPerformed

    private void botaoRemoverActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoRemoverActionPerformed
    {//GEN-HEADEREND:event_botaoRemoverActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
         atores.remove(jList1.getSelectedIndex());   
    }//GEN-LAST:event_botaoRemoverActionPerformed

    private void botaoLocalizaActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoLocalizaActionPerformed
    {//GEN-HEADEREND:event_botaoLocalizaActionPerformed
        // TODO adicione seu c?digo de manipula??o aqui:
       pesquisa();
    }//GEN-LAST:event_botaoLocalizaActionPerformed

    private void BotaoAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoAdicionarActionPerformed
// TODO add your handling code here:
        atores.addElement(this.jtfAtoresPrinc.getText());
        this.jList1.setModel(atores);
        this.jtfAtoresPrinc.setText("");
        
    }//GEN-LAST:event_BotaoAdicionarActionPerformed

    private void botaoProcurarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoProcurarActionPerformed
    {//GEN-HEADEREND:event_botaoProcurarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        JFileChooser cartaz = new JFileChooser();
        cartaz.setDialogTitle("..:: ABRIR CARTAZ ::..");
        //cartaz.setDialogType(JFileChooser.OPEN_DIALOG);
        //cartaz.setSelectedFile(File)
        cartaz.showDialog(null,"Abrir");
        String endereco = ((File)cartaz.getSelectedFile()).getPath();
        ImageIcon img = new ImageIcon(endereco);
        jlImagen.setIcon(img);
        f.setcartaz(cartaz.getName(cartaz.getSelectedFile()));
    }//GEN-LAST:event_botaoProcurarActionPerformed
    
    private void editar()
    {
        int  l = tblFilmes.getSelectedRow();
        String id = tblFilmes.getValueAt(l,0).toString();
        ArrayList<String> ator = new ArrayList<String>();
        
        f.setId(id);
        f.obter();
        limpa();
        jtfTitulo.setText(f.gettitulo());
        jtfSubTitulo.setText(f.getsubtitulo());
        jtfCodigo.setText(f.getcodigo());
        jtfDuracao.setText(f.getduracao());
        jtfProdutora.setText(f.getprodutora());
        jtfPais.setText(f.getpais());
        jtfdataestreia.setText(f.getdataesteia());
        jtfClassificacao.setText(f.getclassificacao());
        jtfDiretor.setText(f.getdiretor());
        jtfTemp_cartaz.setText(f.gettempoCartaz());
        jcbDublado.setSelected(f.getdublado());
        jTextArea1.setText(f.getSinopse());   
        ator = f.getAtorPrinc();
        if(! f.getcartaz().equals(""))
        {            
           //JOptionPane.showMessageDialog(null,path+f.getcartaz());
           ImageIcon img = new ImageIcon(path+f.getcartaz());
           jlImagen.setIcon(img);
        }  
        for(int i=0;i < ator.size();i++)
        {
             atores.addElement(ator.get(i));
                 
        }
        this.jList1.setModel(atores);
        jTabbedPane1.setSelectedIndex(1);
        grava=false;        
    }
    private void pesquisa()
    {
        String[] colunas = new String[]{"C?digo","T?tulo","Diretor","G?nero","Classifica??o"};  
        String[][] dados = new String[][]{{}};
        filme = new DefaultTableModel(dados,colunas);
        String sql;
        ResultSet rs;
        String parametro;
        if(botaoclassificacao.isSelected())
            parametro = "classificacao";
        else if(botaogenero.isSelected())
            parametro = "genero";
        else
            parametro = "titulo";
        try
        {
            sql= "SELECT filme.id_filme, filme.titulo, filme.diretor, filme.genero, filme.classificacao FROM filme WHERE LOWER(filme."+parametro+") LIKE LOWER('%"+txtPesquisa.getText()+"%')";
            rs = bd.executeQueryRs(sql);
            if(bd.Error){
                JOptionPane.showMessageDialog(null,bd.ErrorMessage);
                return;
            }
            String filmes[] = new String[5];
            int aux = 0;
            while( rs.next())
            {
                filmes[0] = rs.getString(1);
                filmes[1] = rs.getString(2);
                filmes[2] = rs.getString(3);
                filmes[3] = rs.getString(4);
                filmes[4] = rs.getString(5);
                filme.addRow(filmes);     
                if (aux == 0){
                    filme.removeRow(0);
                }
                aux++;
            }
            tblFilmes.setModel(filme);
            
        }
        catch(SQLException e)
        {
            JOptionPane.showMessageDialog(null,e);
        }
    }
    private void limpa()
    {
        jtfTitulo.setText("");
        jtfSubTitulo.setText("");
        jtfCodigo.setText("");
        jtfDuracao.setText("");
        jtfProdutora.setText("");
        jtfPais.setText("");
        jtfdataestreia.setText("");
        jtfClassificacao.setText("");
        jtfDiretor.setText("");
        jtfTemp_cartaz.setText("");
        jtfAtoresPrinc.setText("");
        txtPesquisa.setText("");
        atores.clear();
        jlImagen.setIcon(null);
        this.jList1.removeAll();
        jTextArea1.setText("");
        filme = (DefaultTableModel) tblFilmes.getModel();  
        filme.setNumRows(0);  
    }
    private void cadastrar()
    {
         f.settitulo(jtfTitulo.getText());
         f.setsubtitulo(jtfSubTitulo.getText());
         f.setcodigo(jtfCodigo.getText());
         f.setgenero((String) this.jComboBox1.getSelectedItem());
         f.setduracao(jtfDuracao.getText());
         f.setprodutora(jtfProdutora.getText());
         f.setpais(jtfPais.getText());
         f.setdataesteia(jtfdataestreia.getText());
         f.setclassificacao(jtfClassificacao.getText());
         f.setdiretor(jtfDiretor.getText());
         f.setdublado(jcbDublado.isSelected());
         f.settempoCartaz(jtfTemp_cartaz.getText());
         f.setSinopse(jTextArea1.getText());
         f.limpaAtores();
         for(int i=0;i<jList1.getModel().getSize();i++){
             f.addAtorPrinc(jList1.getModel().getElementAt(i).toString());
         }
         if(grava){
            if(f.gravar())
               mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
        }  
        else{
            if(f.atualizar())
                mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
        }
        JOptionPane.showMessageDialog(null,mensagem);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotaoAdicionar;
    private javax.swing.JLabel JlTitulo;
    private javax.swing.JButton botaoEditar;
    private javax.swing.JButton botaoLocaliza;
    private javax.swing.JButton botaoProcurar;
    private javax.swing.JButton botaoRemover;
    private javax.swing.JButton botaocadastrar;
    private javax.swing.JRadioButton botaoclassificacao;
    private javax.swing.JRadioButton botaogenero;
    private javax.swing.JButton botaonovo;
    private javax.swing.JRadioButton botaotitulo;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel cadFilmes;
    private javax.swing.JPanel consFilmes;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JCheckBox jcbDublado;
    private javax.swing.JLabel jlAtoresPrinc;
    private javax.swing.JLabel jlClassificacao;
    private javax.swing.JLabel jlCodigo;
    private javax.swing.JLabel jlDatEstreia;
    private javax.swing.JLabel jlDiretor;
    private javax.swing.JLabel jlDuracao;
    private javax.swing.JLabel jlGenero;
    private javax.swing.JLabel jlImagen;
    private javax.swing.JLabel jlPais;
    private javax.swing.JLabel jlProdutora;
    private javax.swing.JLabel jlSinopse;
    private javax.swing.JLabel jlSubTitulo;
    private javax.swing.JPanel jpCadFilmes;
    private javax.swing.JPanel jpCadfilme;
    private javax.swing.JTextField jtfAtoresPrinc;
    private javax.swing.JTextField jtfClassificacao;
    private javax.swing.JTextField jtfCodigo;
    private javax.swing.JTextField jtfDiretor;
    private javax.swing.JTextField jtfDuracao;
    private javax.swing.JTextField jtfPais;
    private javax.swing.JTextField jtfProdutora;
    private javax.swing.JTextField jtfSubTitulo;
    private javax.swing.JTextField jtfTemp_cartaz;
    private javax.swing.JTextField jtfTitulo;
    private javax.swing.JFormattedTextField jtfdataestreia;
    private javax.swing.JTable tblFilmes;
    private javax.swing.JTextField txtPesquisa;
    // End of variables declaration//GEN-END:variables
    private filme f;
    private String m[][];
    private boolean grava = true;
    DefaultListModel atores;
    DefaultTableModel filme;
    private String mensagem; 
    private MaskFormatter formatadata;
}
